package com.dly.blog.controller;

import com.dly.blog.annotation.IgnoreAccess;
import com.dly.blog.domain.dto.ImageCaptchaDTO;
import com.dly.blog.msg.R;
import com.dly.blog.service.EmailCaptchaService;
import com.dly.blog.service.ImageCaptchaService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.AllArgsConstructor;
import org.springframework.boot.actuate.endpoint.web.annotation.RestControllerEndpoint;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import reactor.core.publisher.Mono;

/**
 * @Author: DaiLiYu
 * @Date: 2023/7/19 14:58
 */
@RestController
@RequestMapping("/captcha")
@AllArgsConstructor
@IgnoreAccess
@Tag(name = "验证码模块")
public class CaptchaController extends BaseController{

    private final ImageCaptchaService imageCaptchaService;

    private final EmailCaptchaService emailCaptchaService;

    @GetMapping("/get")
    @Operation(summary = "获取图片验证码")
    public ResponseEntity<R<ImageCaptchaDTO>> getCaptcha(){
        return operate(()->this.successDate(imageCaptchaService.imageCaptcha()));
    }

    @PostMapping("/sendEmail")
    @Operation(summary = "发送邮箱验证码")
    @Parameter(name = "email", description = "邮箱")
    public ResponseEntity<R<Void>> sendEmailCaptcha(String email){
        emailCaptchaService.send(email);
        return operate(this::success);
    }

}
